package orm

import (
	"fmt"
)

// 相似条件
type condLike struct {
	field   string
	pattern string
}

// 不相似条件
type condNotLike struct {
	field   string
	pattern string
}

// 相似
func Like(field string, pattern string) Cond {
	return &condLike{
		field:   field,
		pattern: pattern,
	}
}

// 不相似
func NotLike(field string, pattern string) Cond {
	return &condNotLike{
		field:   field,
		pattern: pattern,
	}
}

func (c *condLike) Not() Cond {
	return NotLike(c.field, c.pattern)
}

func (c *condNotLike) Not() Cond {
	return Like(c.field, c.pattern)
}

func (c *condLike) Gen(args *[]interface{}, param func() string, colname func(string) string) string {
	*args = append(*args, c.pattern)
	return fmt.Sprintf("%v LIKE %v", colname(c.field), param())
}

func (c *condNotLike) Gen(args *[]interface{}, param func() string, colname func(string) string) string {
	*args = append(*args, c.pattern)
	return fmt.Sprintf("%v NOT LIKE %v", colname(c.field), param())
}
